/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package luft27.comm.dozor;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Arrays;

/**
 *
 * @author amalikov
 */
public class Telemetry implements MessagePayload {
	public byte state;
	public short roll;
	public short pitch;
	public short heading;
	public short ias;
	public short baroAlt;
	public short vs;
	public short directAlt;
	public short course;
	public short gs;
	public float latitude;
	public float longitude;
	public short altitude;
	public short rpm;
	public short temp1;
	public short temp2;
	public byte aileron;
	public byte elevator;
	public byte rudder;
	public byte throttle;
	public byte flaps;
	public byte activeWpt;
	public short z;
	public short s;
	
	@Override
	public byte[] get() {
		ByteBuffer bb = ByteBuffer.allocate(256).order(ByteOrder.LITTLE_ENDIAN);
		bb.put(state);
		bb.putShort(roll);
		bb.putShort(pitch);
		bb.putShort(heading);
		bb.putShort(ias);
		bb.putShort(baroAlt);
		bb.putShort(vs);
		bb.putShort(directAlt);
		bb.putShort(course);
		bb.putShort(gs);
		bb.putFloat(latitude);
		bb.putFloat(longitude);
		bb.putShort(altitude);
		bb.putShort(rpm);
		bb.putShort(temp1);
		bb.putShort(temp2);
		bb.put(aileron);
		bb.put(elevator);
		bb.put(rudder);
		bb.put(throttle);
		bb.put(flaps);
		bb.put(activeWpt);
		bb.putShort(z);
		bb.putShort(s);
		return Arrays.copyOf(bb.array(), bb.position());
	}

	@Override
	public void set(byte[] data) {
		ByteBuffer bb = ByteBuffer.wrap(data).order(ByteOrder.LITTLE_ENDIAN);
		state = bb.get();
		roll = bb.getShort();
		pitch = bb.getShort();
		heading = bb.getShort();
		ias = bb.getShort();
		baroAlt = bb.getShort();
		vs = bb.getShort();
		directAlt = bb.getShort();
		course = bb.getShort();
		gs = bb.getShort();
		latitude = bb.getFloat();
		longitude = bb.getFloat();
		altitude = bb.getShort();
		rpm = bb.getShort();
		temp1 = bb.getShort();
		temp2 = bb.getShort();
		aileron = bb.get();
		elevator = bb.get();
		rudder = bb.get();
		throttle = bb.get();
		flaps = bb.get();
		activeWpt = bb.get();
		z = bb.getShort();
		s = bb.getShort();
	}
	
}
